import Vue from 'vue';
export default {
  install(Vue) {
    Vue.prototype.$setCookie = (cookie) =>{
      let item = cookie || {};
      if(item.expires){
        document.cookie = `${item['cookie']}=${item['value']}; expires=${item['expires']}`;
      }else{
        document.cookie = `${item['cookie']}=${item['value']}`
      }
    };

    Vue.prototype.$getCookie = (str) =>{
      let cookie  = {};
      let cookies = document.cookie.split(';').map(item=>item.replace(' ','').split('='));
      cookies.forEach(item => {
        cookie[item[0]] = item[1]
      });
      return cookie[str];
    };

    Vue.prototype.$removeCookie = (str) =>{
      let oDate = new Date();

      oDate.setDate(oDate.getDate()-1);
      console.log('$removeCookie');
      document.cookie = `${str}=${1};expires=${oDate}`;
    
    };
  }
}